//------------------------------------------------------------------------------
#include <QtDebug>
#include <QByteArray>
#include "CMarkDown.h"
//------------------------------------------------------------------------------
extern "C" {
	#include <markdown.h>
	#include <renderers.h>
}// extern "C"
//------------------------------------------------------------------------------
QString CMarkDown::toHtml(QString markDownStr) {
	struct buf *ib, *ob;
	const struct mkd_renderer *hrndr;//, *xrndr;
	const struct mkd_renderer **prndr;
	char *buffer=markDownStr.toUtf8().data();
	int l=strlen(buffer)+1;
	QString ret;
	
	hrndr = &mkd_html;
	//xrndr = &mkd_xhtml;
	prndr = &hrndr;
	
	ib=bufnew(l);
	ib->size=l;
	bufgrow(ib, l);
	strcpy(ib->data, buffer);
	
	ob = bufnew(64);
	markdown(ob, ib, *prndr);
	
	ret=QString::fromUtf8(ob->data, ob->size);
	
	bufrelease(ib);
	bufrelease(ob);
	
	return ret;
}
//------------------------------------------------------------------------------